package com.weex.app;

import android.app.Application;
import android.content.Context;

import com.alibaba.android.bindingx.plugin.weex.BindingX;
import com.alibaba.weex.plugin.loader.WeexPluginContainer;
import com.taobao.weex.InitConfig;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.common.WXException;
import com.weex.app.extend.Hash;
import com.weex.app.extend.ImageAdapter;
import com.weex.app.extend.ImageAppIco;
import com.weex.app.extend.Permission;
import com.weex.app.extend.WXEventModule;
import com.weex.app.extend.WxAndroidOs;
import com.weex.app.extend.WxPackageManager;
import com.weex.app.extend.WxUsageStats;
import com.weex.app.extend.WxWcdb;
import com.weex.app.util.AppConfig;


public class WXApplication extends Application {
  private void initDebugEnvironment(String host) {
      WXEnvironment.sRemoteDebugMode = true;
      WXEnvironment.sDebugServerConnectable = true;
      WXEnvironment.sRemoteDebugProxyUrl = "ws://"+host+":8088/debugProxy/native/e60a5230-27c9-4796-b0b5-ba3610fd1932";
        //WXSDKEngine.reload();
  }
  
  @Override
  public void onCreate() {

    super.onCreate();
    
    if(true){
    //if(false){
        initDebugEnvironment("192.168.2.123");
    }else{
        try {
            BindingX.register();
        } catch (WXException e) {
            e.printStackTrace();
        }
    }

    WXSDKEngine.addCustomOptions("appName", "Phone.Life");
    WXSDKEngine.addCustomOptions("appGroup", "BeiKun");

    WXSDKEngine.initialize(
        this,
        new InitConfig.Builder().setImgAdapter(
            new ImageAdapter()
        ).build()
    );


    try {
      WXSDKEngine.registerModule("event", WXEventModule.class);
      WXSDKEngine.registerModule("PackageManager", WxPackageManager.class);
      WXSDKEngine.registerModule("UsageStats", WxUsageStats.class);
      WXSDKEngine.registerModule("Permission", Permission.class);
      WXSDKEngine.registerModule("AndroidOs", WxAndroidOs.class);
      WXSDKEngine.registerModule("Hash", Hash.class);
      WXSDKEngine.registerModule("Wcdb", WxWcdb.class);

    } catch (WXException e) {
      e.printStackTrace();
    }
    
    
    Context context = getApplicationContext();
    ImageAppIco.getInstance().init(context);
    AppConfig.init(this);
    WeexPluginContainer.loadAll(this);
  }

}
